
var app = getApp();
let statusList={
  '400':'操作失败'
}
const http = (method, query, data,head={}) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: app.globalData.url+query,
      header: {
        'content-type': 'application/json',
         'token':wx.getStorageSync('token')
       },
      data,
      method,
      success: res => {
        let {statusCode}=res
          wx.showToast({
            title: statusList[statusCode],
            icon:'none'
          })
        resolve(res)
      },
      fail: err => {
        reject(err)
      }
    })
  })
}

const get = (query,data) => {
  return http('get', query,data)
}
const header = (query,header) => {
  return http('get', query,{},header)
}
const post = (query, data) => {
  return http('post', query, data)
}
const put = (query, data,head={}) => {
  return http('put', query, data,head)
}
module.exports = {
  get,
  post,
  put,
  header
}